    % Get portfolio by market code, number of stocks, stock codes, and weights
% Input: market_code, number_of_stocks, stock_codes, porfolio_weights
% Output: portfolio_codes, porfolio_weights, portfolio_date, and portfolio_close_price
function [portfolio_codes_t porfolio_weights_t portfolio_date_t portfolio_close_price_t portfolio_volume_t] = getPortfolio(market_code, number_of_stocks, stock_codes, porfolio_weights)
    tic;
    % the minimum of the number of stocks
    MIN_NUMBER_OF_STOCKS = 5;
    % the maximum of the number of stocks
    MAX_NUMBER_OF_STOCKS = 10;

    % if the market is null => random market
    if (isempty(market_code))
        market_code_t = getRandomMarketCode();
        market_code_t = cell2mat(market_code);
    else
        market_code_t = market_code;
    end
    
    % if the number of stocks is null => random number of stocks
    if (isempty(number_of_stocks))
        number_of_stocks_t = randi([MIN_NUMBER_OF_STOCKS, MAX_NUMBER_OF_STOCKS]);
    else
        number_of_stocks_t = number_of_stocks;
    end
    
    % if vector weight is null => random vector weight
    if (isempty(porfolio_weights))
        porfolio_weights_t = getRandomWeights(number_of_stocks_t)
    else
        porfolio_weights_t = porfolio_weights;
    end
        
    % if the list of stock codes in portfolio is null => random the list of
    % stock codes
    if (isempty(stock_codes))
        stock_codes_t = getRandomStockCodes(market_code_t, number_of_stocks_t, 250, 5000)
    else
        stock_codes_t = stock_codes;
    end
    
    [portfolio_codes_t portfolio_date_t portfolio_close_price_t portfolio_volume_t] = getIndex(market_code_t);
    % load all stocks data and normalize data
    delta_index = 0;
    for stock_codes_index = 1:number_of_stocks_t
        % load data of a stock
        [code_temp date_temp price_temp volume_temp] = getStock(cell2mat(stock_codes_t(stock_codes_index + delta_index)));
        portfolio_codes_t = [portfolio_codes_t; {code_temp}];
        % normalize data
        if (length(portfolio_date_t) <= 250)
            break;
        else
            [portfolio_date_t portfolio_close_price_t portfolio_volume_t] = getIntersectOfStockTable(stock_codes_index, portfolio_date_t, portfolio_close_price_t, portfolio_volume_t, date_temp, price_temp, volume_temp);
        end
    end
    if (length(portfolio_volume_t)<=250)
        [portfolio_codes_t porfolio_weights_t portfolio_date_t portfolio_close_price_t portfolio_volume_t] = getPortfolio(market_code, number_of_stocks, stock_codes, porfolio_weights);
    end
    toc;
end